/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlaylistCellWithArtPanel.java
 *
 * Created on Mar 8, 2009, 2:36:51 PM
 */
package com.bff.slimserver.musicjukebox.ui.components.favorites;

import com.bff.slimserver.music.exceptions.PlaylistException;
import com.bff.slimserver.musicjukebox.lib.ArtManager;
import com.bff.bjj.ui.component.ColorProperties;
import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import com.bff.slimserver.musicjukebox.ui.components.AlbumCellPanel;
import com.bff.bjj.ui.component.BJJPanel;
import java.awt.Color;
import java.awt.Component;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import org.bff.slimserver.SlimPlaylist;
import org.bff.slimserver.SlimServer;
import org.bff.slimserver.exception.SlimConnectionException;
import org.bff.slimserver.musicobjects.radio.SlimRadioAudioDetails;

/**
 *
 * @author Music
 */
public class FavoritesItemCellPanel extends javax.swing.JPanel implements FavoritesCellPanelIface {

    private SlimServer slimServer;
    private SlimPlaylist playlist;
    private SlimRadioAudioDetails radioItem;

    /** Creates new form PlaylistCellWithArtPanel */
    public FavoritesItemCellPanel(SlimRadioAudioDetails radioItem) {
        setRadioItem(radioItem);

        try {
            setSlimServer(JukeboxProperties.getInstance().getSlimServer());
        } catch (SlimConnectionException ex) {
            Logger.getLogger(FavoritesItemCellPanel.class.getName()).log(Level.SEVERE, null, ex);
        }

        try {
            this.playlist = JukeboxProperties.getInstance().getPlaylist();
        } catch (PlaylistException ex) {
            Logger.getLogger(AlbumCellPanel.class.getName()).log(Level.SEVERE, null, ex);
        }

        initComponents();

        try {
            tpDetails.setText("\n\n" + (radioItem.getTitle() == null ? radioItem.getName() : radioItem.getTitle()) +
                    "\n\n" + radioItem.getSubText());

            if (radioItem.getImageUrl() != null) {

                ImageIcon icon = new ImageIcon(ArtManager.getArt(radioItem));

                lblIcon.setIcon(icon);
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Something is probably null");
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        detailPanel = new javax.swing.JPanel();
        tpDetails = new javax.swing.JTextPane();
        jPanel1 = new BJJPanel();
        btnAdd = new com.bff.slimserver.musicjukebox.ui.components.favorites.FavoritesAddButton(getRadioItem());
        btnAdd.setText(null);
        jPanel2 = new BJJPanel();
        lblIcon = new javax.swing.JLabel();

        setLayout(new java.awt.BorderLayout());

        detailPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        detailPanel.setLayout(new java.awt.BorderLayout());

        tpDetails.setEditable(false);
        tpDetails.setOpaque(false);
        detailPanel.add(tpDetails, java.awt.BorderLayout.PAGE_START);

        add(detailPanel, java.awt.BorderLayout.CENTER);

        jPanel1.setLayout(new java.awt.GridBagLayout());
        jPanel1.add(btnAdd, new java.awt.GridBagConstraints());

        add(jPanel1, java.awt.BorderLayout.EAST);

        jPanel2.add(lblIcon);

        add(jPanel2, java.awt.BorderLayout.WEST);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JPanel detailPanel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel lblIcon;
    private javax.swing.JTextPane tpDetails;
    // End of variables declaration//GEN-END:variables

    public void setEven() {
        setBackground(ColorProperties.LIST_BACKGROUND_EVEN);
    }

    public void setOdd() {
        setBackground(ColorProperties.LIST_BACKGROUND_ODD);
    }

    public void setCurrentPlaying() {
        setForeground(ColorProperties.PLAYLIST_CURRENT_PLAYING_FOREGROUND);
    }

    public void setSelected() {
        setForeground(ColorProperties.LIST_FOREGROUND_SELECTED);
        setBackground(ColorProperties.LIST_BACKGROUND_SELECTED);
        tpDetails.setBackground(ColorProperties.LIST_BACKGROUND_SELECTED);
        tpDetails.setForeground(ColorProperties.LIST_FOREGROUND_SELECTED);
        lblIcon.setBackground(ColorProperties.LIST_BACKGROUND_SELECTED);
        lblIcon.setForeground(ColorProperties.LIST_FOREGROUND_SELECTED);
    }

    public void setNotSelected() {
        setForeground(ColorProperties.LIST_FOREGROUND);
    }

    @Override
    public void setBackground(Color bg) {
        super.setBackground(bg);
        if (detailPanel != null) {
            detailPanel.setBackground(bg);
            jPanel1.setBackground(bg);
            jPanel2.setBackground(bg);
        }
    }

    @Override
    public void setForeground(Color fg) {
        super.setForeground(fg);
        if (detailPanel != null) {
            detailPanel.setForeground(fg);
            jPanel1.setForeground(fg);
            jPanel2.setForeground(fg);
        }
        setLabelColors(fg);
    }

    private void setLabelColors(Color color) {
        //if (lblIcon != null) {
        if (tpDetails != null) {
            tpDetails.setForeground(color);
            lblIcon.setForeground(color);
        }
    }

    @Override
    public Component getPanel() {
        return this;
    }

    public void setCurrent() {
        setLabelColors(ColorProperties.PLAYLIST_CURRENT_PLAYING_FOREGROUND);
    }

    public void setNotCurrent() {
        setLabelColors(ColorProperties.LIST_FOREGROUND_SELECTED);
    }

    /**
     * @return the slimServer
     */
    public SlimServer getSlimServer() {
        return slimServer;
    }

    /**
     * @param slimServer the slimServer to set
     */
    public void setSlimServer(SlimServer slimServer) {
        this.slimServer = slimServer;
    }

    /**
     * @return the radioItem
     */
    public SlimRadioAudioDetails getRadioItem() {
        return radioItem;
    }

    /**
     * @param radioItem the radioItem to set
     */
    public void setRadioItem(SlimRadioAudioDetails radioItem) {
        this.radioItem = radioItem;
    }

    /**
     * @return the playlist
     */
    public SlimPlaylist getPlaylist() {
        return playlist;
    }

    /**
     * @param playlist the playlist to set
     */
    public void setPlaylist(SlimPlaylist playlist) {
        this.playlist = playlist;
    }
}
